import u3 import traceback from datetime import datetime import csv import sys import time import math # MAX_REQUESTS is the number of packets to be read. MAX_REQUESTS = 1 # ## At high frequencies ( >5 kHz), the number of samples will be MAX_REQUESTS times 48 (packets per request) times 25 (samples per packet). d = u3.U3() # ## To learn if the U3 is an HV d.configU3() # ## For applying the proper calibration to readings. d.getCalibrationData() # ##Assigns FIO4 as Digital input timer d.configIO(TimerCounterPinOffset=4, NumberOfTimersEnabled=1) # u3.Timer0Config(TimerMode=12, Value=0) # ##6=48MHz clock base, 48= clock divisor. 48MHz/48=1MHz samples taken. d.configTimerClock(6,48) #u3.Timer(timer=0) d.streamConfig(NumChannels=4, PChannels=[0, 1, 2, 200], NChannels=[31, 31, 31, 31], Resolution=1, ScanFrequency=2000) try: print ("start stream",) d.streamStart() start = datetime.now() print (start) missed = 0 dataCount = 0 packetCount = 0 for r in d.streamData(): if r is not None: # Our stop condition if dataCount >= MAX_REQUESTS: break if r['errors'] != 0: print ("Error: %s ; " % r['errors'], datetime.now()) if r['numPackets'] != d.packetsPerRequest: print ("----- UNDERFLOW : %s : " % r['numPackets'], datetime.now()) if r['missed'] != 0: missed += r['missed'] print ("+++ Missed ", r['missed']) print(r['AIN200']) else: # Got no data back from our read. # This only happens if your stream isn't faster than the # the USB read timeout, ~1 sec. print ("No data", datetime.now()) finally: stop = datetime.now() d.streamStop() print ("stream stopped.") d.close()